package com.qihang.librarymanage.jframe.user;

import com.qihang.librarymanage.utils.Theme;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;

public class BookDetails extends JFrame {
    // 书籍信息类
    private static class Book {
        private final String title;
        private final String author;
        private final double price;
        private final String description;
        private final String coverPath;

        public Book(String title, String author, double price, String description, String coverPath) {
            this.title = title;
            this.author = author;
            this.price = price;
            this.description = description;
            this.coverPath = coverPath;
        }
    }
    
    // UI 组件
    private final Book currentBook;
    private ImageIcon passedCoverIcon;
    private Color primaryColor = new Color(63, 81, 181);
    private Color accentColor = new Color(255, 64, 129);
    private Color bgStartColor = new Color(240, 242, 245);
    private Color bgEndColor = new Color(225, 232, 238);
    
    // 用户信息 - 模拟数据
    private String userName = "张三";
    private String userAvatar = "/images/avatar.png";

    public BookDetails() {
        // 应用主题样式
        new Theme(1); // 使用FlatLightLaf主题
        
        // 初始化示例书籍数据（实际应用中应从数据库获取）
        currentBook = new Book(
            "雪中悍刀行", 
            "烽火戏诸侯", 
            220.0, 
            "简介：有个白狐狸儿脸，佩双刀绣冬春雷，要做那天下第一。湖底有白发老魁憋屈吃拳。缺门牙老仆背剑闯关。山上有骑青牛的年轻师叔祖，不教下山。有骑鲸越北的旦夕杀不尽的江东李家子弟。这个江湖，高人出手便是世出绝尘，女侠行走江湖要遮遮掩掩杀人，宗派要跟庙堂打好关系。而主角，则满酒满刀，把江湖捅了个通透。",
            "/images/1.jpg"
        );
        
        initUI();
    }
    
    // 添加新的构造函数，接收从BookInfo传递的参数
    public BookDetails(String title, String author, double price, String description, ImageIcon cover) {
        // 应用主题样式
        new Theme(1);
        
        // 将ImageIcon转换为路径，假设使用默认路径
        String coverPath = "/images/default_book.png";
        
        // 创建Book对象
        currentBook = new Book(title, author, price, description, coverPath);
        
        // 保存传入的封面图标供后续使用
        this.passedCoverIcon = cover;
        
        initUI();
    }
    
    private void initUI() {
        setupFrame();
        
        // 创建主面板
        JPanel mainPanel = createMainPanel();
        setContentPane(mainPanel);
        
        // 添加返回按钮
        addBackButton();
        
        // 添加用户信息
        addUserInfo();
        
        // 创建内容面板
        JPanel contentPanel = createContentPanel();
        mainPanel.add(contentPanel, BorderLayout.CENTER);
        
        setVisible(true);
    }
    
    private void setupFrame() {
        setTitle("图书详情");
        setSize(1200, 750);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setResizable(false);
    }
    
    private JPanel createMainPanel() {
        return new JPanel(new BorderLayout()) {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2d = (Graphics2D) g.create();
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                
                // 创建渐变背景
                GradientPaint gradient = new GradientPaint(
                    0, 0, bgStartColor,
                    0, getHeight(), bgEndColor
                );
                g2d.setPaint(gradient);
                g2d.fillRect(0, 0, getWidth(), getHeight());
                
                // 添加顶部装饰条
                g2d.setPaint(new GradientPaint(
                    0, 0, primaryColor,
                    getWidth(), 0, new Color(100, 123, 255)
                ));
                g2d.fillRect(0, 0, getWidth(), 5);
                
                g2d.dispose();
            }
        };
    }
    
    private void addBackButton() {
        JButton backBtn = new JButton("返回");
        backBtn.setFont(new Font("微软雅黑", Font.BOLD, 14));
        backBtn.setForeground(Color.WHITE);
        backBtn.setBackground(primaryColor);
        backBtn.setFocusPainted(false);
        backBtn.setBounds(30, 20, 100, 40);
        backBtn.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
        
        // 圆角效果
        backBtn.putClientProperty("JButton.buttonType", "roundRect");
        
        // 绝对定位按钮层
        JLayeredPane layeredPane = getLayeredPane();
        JPanel backPanel = new JPanel(null);
        backPanel.setOpaque(false);
        backPanel.setBounds(0, 0, 200, 80);
        backPanel.add(backBtn);
        layeredPane.add(backPanel, JLayeredPane.PALETTE_LAYER);
        
        // 添加鼠标悬停效果
        backBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                backBtn.setBackground(new Color(83, 109, 254));
            }
            
            public void mouseExited(java.awt.event.MouseEvent evt) {
                backBtn.setBackground(primaryColor);
            }
        });
        
        // 按钮点击事件
        backBtn.addActionListener(e -> {
            dispose();
            new BookInfo();
        });
    }
    
    // 添加用户信息区域
    private void addUserInfo() {
        // 创建用户信息面板
        JPanel userPanel = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2d = (Graphics2D) g.create();
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                
                // 绘制半透明背景
                g2d.setColor(new Color(255, 255, 255, 180));
                g2d.fillRoundRect(0, 0, getWidth(), getHeight(), 15, 15);
                
                // 绘制边框
                g2d.setColor(new Color(200, 200, 200, 100));
                g2d.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 15, 15);
                
                g2d.dispose();
            }
        };
        userPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 5));
        userPanel.setOpaque(false);
        userPanel.setBounds(getWidth() - 200, 15, 180, 50);
        
        // 创建用户头像
        JLabel avatarLabel = new JLabel();
        avatarLabel.setPreferredSize(new Dimension(40, 40));
        
        // 加载用户头像
        try {
            java.net.URL imgUrl = getClass().getResource(userAvatar);
            if (imgUrl != null) {
                ImageIcon icon = new ImageIcon(imgUrl);
                Image img = icon.getImage().getScaledInstance(40, 40, Image.SCALE_SMOOTH);
                ImageIcon scaledIcon = new ImageIcon(img);
                avatarLabel.setIcon(createCircularIcon(scaledIcon));
            } else {
                // 默认头像（首字母）
                avatarLabel.setOpaque(true);
                avatarLabel.setBackground(new Color(63, 81, 181));
                avatarLabel.setForeground(Color.WHITE);
                avatarLabel.setFont(new Font("微软雅黑", Font.BOLD, 20));
                avatarLabel.setText(userName.substring(0, 1));
                avatarLabel.setHorizontalAlignment(SwingConstants.CENTER);
                avatarLabel.setVerticalAlignment(SwingConstants.CENTER);
            }
        } catch (Exception e) {
            // 默认头像（首字母）
            avatarLabel.setOpaque(true);
            avatarLabel.setBackground(new Color(63, 81, 181));
            avatarLabel.setForeground(Color.WHITE);
            avatarLabel.setFont(new Font("微软雅黑", Font.BOLD, 20));
            avatarLabel.setText(userName.substring(0, 1));
            avatarLabel.setHorizontalAlignment(SwingConstants.CENTER);
            avatarLabel.setVerticalAlignment(SwingConstants.CENTER);
        }
        
        // 用户名标签
        JLabel nameLabel = new JLabel(userName);
        nameLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
        nameLabel.setForeground(new Color(60, 60, 60));
        
        // 下拉菜单图标
        JLabel menuIcon = new JLabel("▼");
        menuIcon.setFont(new Font("微软雅黑", Font.PLAIN, 12));
        menuIcon.setForeground(new Color(100, 100, 100));
        
        // 添加到面板
        userPanel.add(avatarLabel);
        userPanel.add(nameLabel);
        userPanel.add(menuIcon);
        
        // 添加点击事件
        userPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                userPanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
            }
            
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                // 创建弹出菜单
                JPopupMenu popupMenu = new JPopupMenu();
                
                // 菜单项
                JMenuItem profileItem = new JMenuItem("个人资料");
                JMenuItem settingsItem = new JMenuItem("设置");
                JMenuItem logoutItem = new JMenuItem("退出登录");
                
                // 设置字体
                Font menuFont = new Font("微软雅黑", Font.PLAIN, 14);
                profileItem.setFont(menuFont);
                settingsItem.setFont(menuFont);
                logoutItem.setFont(menuFont);
                
                // 添加菜单项
                popupMenu.add(profileItem);
                popupMenu.add(settingsItem);
                popupMenu.addSeparator();
                popupMenu.add(logoutItem);
                
                // 显示菜单
                popupMenu.show(userPanel, 0, userPanel.getHeight());
            }
        });
        
        // 添加到窗口
        JLayeredPane layeredPane = getLayeredPane();
        layeredPane.add(userPanel, JLayeredPane.PALETTE_LAYER);
    }
    
    // 创建圆形头像
    private ImageIcon createCircularIcon(ImageIcon icon) {
        int diameter = Math.min(icon.getIconWidth(), icon.getIconHeight());
        BufferedImage image = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = image.createGraphics();
        
        // 抗锯齿和高质量渲染
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        
        // 绘制圆形剪切区域
        g2.setClip(new java.awt.geom.Ellipse2D.Float(0, 0, diameter, diameter));
        g2.drawImage(icon.getImage(), 0, 0, diameter, diameter, null);
        
        // 添加边框
        g2.setColor(new Color(255, 255, 255, 100));
        g2.setStroke(new BasicStroke(2));
        g2.drawOval(0, 0, diameter-1, diameter-1);
        
        g2.dispose();
        
        return new ImageIcon(image);
    }
    
    private JPanel createContentPanel() {
        // 主内容面板 - 使用卡片布局
        JPanel contentPanel = new JPanel(new BorderLayout(30, 0)) {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                // 添加半透明效果
                Graphics2D g2d = (Graphics2D) g.create();
                g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
                g2d.dispose();
            }
        };
        contentPanel.setOpaque(false);
        contentPanel.setBorder(BorderFactory.createEmptyBorder(70, 50, 50, 50));
        
        // 创建卡片式内容面板
        JPanel cardPanel = new JPanel(new BorderLayout(30, 0)) {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2d = (Graphics2D) g.create();
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                
                // 绘制圆角矩形背景
                RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(
                    0, 0, getWidth(), getHeight(), 20, 20);
                g2d.setColor(Color.WHITE);
                g2d.fill(roundedRectangle);
                
                // 添加卡片阴影效果
                for (int i = 0; i < 5; i++) {
                    g2d.setColor(new Color(0, 0, 0, 10 - i * 2));
                    g2d.draw(new RoundRectangle2D.Float(
                        i, i, getWidth() - 2 * i, getHeight() - 2 * i, 20, 20));
                }
                
                g2d.dispose();
            }
        };
        cardPanel.setOpaque(false);
        cardPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        
        // 添加封面面板到左侧
        cardPanel.add(createCoverPanel(), BorderLayout.WEST);
        
        // 添加信息面板到右侧
        cardPanel.add(createInfoPanel(), BorderLayout.CENTER);
        
        contentPanel.add(cardPanel, BorderLayout.CENTER);
        
        return contentPanel;
    }
    
    private JPanel createCoverPanel() {
        // 创建封面标签
        JLabel coverLabel = new JLabel();
        int imgWidth = 300;
        int imgHeight = 400;
        coverLabel.setPreferredSize(new Dimension(imgWidth, imgHeight));
        
        // 加载图片
        if (passedCoverIcon != null) {
            // 如果有传入的封面图片，使用它
            loadBookCoverFromIcon(coverLabel, passedCoverIcon, imgWidth, imgHeight);
        } else {
            // 否则使用路径加载
            loadBookCover(coverLabel, currentBook.coverPath, imgWidth, imgHeight);
        }
        
        // 封面面板（卡片式设计）
        JPanel coverPanel = new JPanel(new BorderLayout()) {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2d = (Graphics2D) g.create();
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                
                // 绘制连续的阴影效果
                int shadowSize = 5;
                int x = (getWidth() - imgWidth) / 2 - shadowSize;
                int y = (getHeight() - imgHeight) / 2 - shadowSize;
                
                // 绘制外部阴影
                for (int i = 0; i < shadowSize; i++) {
                    float alpha = 0.1f - (i * 0.02f);
                    if (alpha < 0) alpha = 0;
                    
                    g2d.setColor(new Color(0, 0, 0, (int)(alpha * 255)));
                    g2d.drawRect(
                        x + i, 
                        y + i, 
                        imgWidth + 2 * (shadowSize - i), 
                        imgHeight + 2 * (shadowSize - i)
                    );
                }
                
                g2d.dispose();
            }
        };
        coverPanel.setOpaque(false);
        coverPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        coverPanel.add(coverLabel, BorderLayout.CENTER);
        
        return coverPanel;
    }
    
    private void loadBookCover(JLabel label, String path, int width, int height) {
        try {
            java.net.URL imgUrl = getClass().getResource(path);
            if (imgUrl != null) {
                ImageIcon icon = new ImageIcon(imgUrl);
                Image img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
                ImageIcon scaledIcon = new ImageIcon(img);
                
                // 创建带圆角的图像
                label.setIcon(createRoundedImageIcon(scaledIcon, 10));
            } else {
                label.setText("[封面图片未找到]");
                label.setHorizontalAlignment(SwingConstants.CENTER);
                label.setFont(new Font("微软雅黑", Font.BOLD, 16));
                label.setForeground(Color.GRAY);
            }
        } catch (Exception e) {
            label.setText("[封面图片加载失败]");
            label.setHorizontalAlignment(SwingConstants.CENTER);
            label.setFont(new Font("微软雅黑", Font.BOLD, 16));
            label.setForeground(Color.GRAY);
        }
    }
    
    // 添加新方法，直接使用ImageIcon
    private void loadBookCoverFromIcon(JLabel label, ImageIcon icon, int width, int height) {
        if (icon != null && icon.getIconWidth() > 0) {
            Image img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
            ImageIcon scaledIcon = new ImageIcon(img);
            
            // 创建带圆角的图像
            label.setIcon(createRoundedImageIcon(scaledIcon, 10));
        } else {
            label.setText("[封面图片未找到]");
            label.setHorizontalAlignment(SwingConstants.CENTER);
            label.setFont(new Font("微软雅黑", Font.BOLD, 16));
            label.setForeground(Color.GRAY);
        }
    }
    
    // 创建圆角图像图标
    private ImageIcon createRoundedImageIcon(ImageIcon icon, int cornerRadius) {
        int width = icon.getIconWidth();
        int height = icon.getIconHeight();
        
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = image.createGraphics();
        
        // 抗锯齿和高质量渲染
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        
        // 绘制圆角矩形
        g2.setClip(new RoundRectangle2D.Float(0, 0, width, height, cornerRadius, cornerRadius));
        g2.drawImage(icon.getImage(), 0, 0, null);
        g2.dispose();
        
        return new ImageIcon(image);
    }
    
    private JPanel createInfoPanel() {
        // 信息区卡片设计
        JPanel infoPanel = new JPanel();
        infoPanel.setOpaque(false);
        infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.Y_AXIS));
        infoPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        
        // 书名 - 使用醒目大标题
        JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        titlePanel.setOpaque(false);
        titlePanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 50));
        titlePanel.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        JLabel nameLabel = new JLabel(currentBook.title);
        nameLabel.setFont(new Font("微软雅黑", Font.BOLD, 32));
        nameLabel.setForeground(primaryColor);
        titlePanel.add(nameLabel);
        
        // 信息分隔线
        JSeparator separator = new JSeparator();
        separator.setForeground(new Color(200, 200, 200));
        separator.setMaximumSize(new Dimension(Integer.MAX_VALUE, 2));
        separator.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        // 作者、价格信息（水平排列）
        JPanel detailsPanel = new JPanel();
        detailsPanel.setLayout(new BoxLayout(detailsPanel, BoxLayout.Y_AXIS));
        detailsPanel.setOpaque(false);
        detailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
        detailsPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
        
        // 作者
        JPanel authorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        authorPanel.setOpaque(false);
        JLabel authorPrefix = new JLabel("作者：");
        authorPrefix.setFont(new Font("微软雅黑", Font.BOLD, 18));
        authorPrefix.setForeground(new Color(100, 100, 100));
        
        JLabel authorValue = new JLabel(currentBook.author);
        authorValue.setFont(new Font("微软雅黑", Font.PLAIN, 18));
        
        authorPanel.add(authorPrefix);
        authorPanel.add(authorValue);
        
        // 价格
        JPanel pricePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        pricePanel.setOpaque(false);
        JLabel pricePrefix = new JLabel("价格：");
        pricePrefix.setFont(new Font("微软雅黑", Font.BOLD, 18));
        pricePrefix.setForeground(new Color(100, 100, 100));
        
        JLabel priceValue = new JLabel("¥" + currentBook.price);
        priceValue.setFont(new Font("微软雅黑", Font.PLAIN, 18));
        priceValue.setForeground(new Color(239, 83, 80)); // 红色价格
        
        pricePanel.add(pricePrefix);
        pricePanel.add(priceValue);
        
        detailsPanel.add(authorPanel);
        detailsPanel.add(Box.createVerticalStrut(5));
        detailsPanel.add(pricePanel);
        
        // 简介标题
        JLabel descTitle = new JLabel("图书简介");
        descTitle.setFont(new Font("微软雅黑", Font.BOLD, 20));
        descTitle.setForeground(new Color(60, 60, 60));
        descTitle.setAlignmentX(Component.LEFT_ALIGNMENT);
        descTitle.setBorder(BorderFactory.createEmptyBorder(15, 0, 10, 0));
        
        // 简介内容面板（带背景色）
        JPanel descBackgroundPanel = new JPanel(new BorderLayout()) {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2d = (Graphics2D) g.create();
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                
                // 创建淡色背景
                RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(
                    0, 0, getWidth(), getHeight(), 10, 10);
                g2d.setColor(new Color(245, 245, 245));
                g2d.fill(roundedRectangle);
                
                g2d.dispose();
            }
        };
        descBackgroundPanel.setOpaque(false);
        descBackgroundPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        descBackgroundPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        // 简介文本区
        JTextArea introArea = new JTextArea(currentBook.description);
        introArea.setLineWrap(true);
        introArea.setWrapStyleWord(true);
        introArea.setEditable(false);
        introArea.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        introArea.setOpaque(false);
        introArea.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        
        JScrollPane introScroll = new JScrollPane(introArea);
        introScroll.setOpaque(false);
        introScroll.getViewport().setOpaque(false);
        introScroll.setBorder(null);
        introScroll.setPreferredSize(new Dimension(500, 180));
        
        descBackgroundPanel.add(introScroll, BorderLayout.CENTER);
        
        // 按钮面板
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
        buttonPanel.setOpaque(false);
        buttonPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0));
        buttonPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
        buttonPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 60));
        
        // 创建三个功能按钮
        JButton borrowButton = createStyledButton("借阅", accentColor);
        JButton favoriteButton = createStyledButton("收藏", new Color(76, 175, 80));
        JButton shareButton = createStyledButton("分享", new Color(3, 169, 244));
        
        // 添加点击事件
        borrowButton.addActionListener(e -> {
            JOptionPane.showMessageDialog(this, 
                "您已成功借阅《" + currentBook.title + "》，请在30天内归还。", 
                "借阅成功", 
                JOptionPane.INFORMATION_MESSAGE);
        });
        
        favoriteButton.addActionListener(e -> {
            JOptionPane.showMessageDialog(this, 
                "已将《" + currentBook.title + "》加入收藏夹。", 
                "收藏成功", 
                JOptionPane.INFORMATION_MESSAGE);
        });
        
        shareButton.addActionListener(e -> {
            JOptionPane.showMessageDialog(this, 
                "分享链接已复制到剪贴板，您可以发送给好友。", 
                "分享成功", 
                JOptionPane.INFORMATION_MESSAGE);
        });
        
        buttonPanel.add(borrowButton);
        buttonPanel.add(Box.createHorizontalStrut(15));
        buttonPanel.add(favoriteButton);
        buttonPanel.add(Box.createHorizontalStrut(15));
        buttonPanel.add(shareButton);
        buttonPanel.add(Box.createHorizontalGlue());
        
        // 添加到主面板
        infoPanel.add(titlePanel);
        infoPanel.add(separator);
        infoPanel.add(Box.createVerticalStrut(10));
        infoPanel.add(detailsPanel);
        infoPanel.add(Box.createVerticalStrut(10));
        infoPanel.add(descTitle);
        infoPanel.add(descBackgroundPanel);
        infoPanel.add(buttonPanel);
        
        return infoPanel;
    }
    
    // 创建统一风格的按钮
    private JButton createStyledButton(String text, Color bgColor) {
        JButton button = new JButton(text);
        button.setFont(new Font("微软雅黑", Font.BOLD, 16));
        button.setForeground(Color.WHITE);
        button.setBackground(bgColor);
        button.setFocusPainted(false);
        button.setPreferredSize(new Dimension(100, 40));
        
        // 设置圆角边框
        button.setBorder(BorderFactory.createEmptyBorder(8, 15, 8, 15));
        button.putClientProperty("JButton.buttonType", "roundRect");
        
        // 添加鼠标悬停效果
        Color darkerColor = bgColor.darker();
        button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                button.setBackground(darkerColor);
                button.setCursor(new Cursor(Cursor.HAND_CURSOR));
            }
            
            public void mouseExited(java.awt.event.MouseEvent evt) {
                button.setBackground(bgColor);
            }
        });
        
        return button;
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(BookDetails::new);
    }
}
